//
//  MIDMainViewController.m
//  20170207
//
//  Created by xuPeng on 2017/9/20.
//  Copyright © 2017年 一直丶黑曼巴. All rights reserved.
//
#import "Header.h"
#import "MIDMainViewController.h"
#import "PicViewController.h"
#import "SleepViewController.h"
#import "HideCellViewController.h"

@interface MIDMainViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,copy)NSArray *titleArray;
@property (nonatomic,strong)UITableView *tableView;
@end

@implementation MIDMainViewController

- (NSArray *)titleArray{

    if (!_titleArray) {
        _titleArray = @[@"图片浏览控件",@"永不休眠",@"隐藏某行cell",@"隐藏某行cell"];
    }
    NSLog(@"++%lu++",(unsigned long)_titleArray.count);
    _titleArray = [_titleArray valueForKeyPath:@"@distinctUnionOfObjects.self"];
    NSLog(@"++%lu++",(unsigned long)_titleArray.count);
    return _titleArray;
}

- (UITableView *)tableView{
    if (!_tableView) { // 如果用self.tableView,会调用属性的setter方法，会导致setter方法的训话调用
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, PW, PH) style:UITableViewStylePlain];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;

        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"实用技巧";
    [self.view addSubview:self.tableView];
}


#pragma 表视图的协议方法和数据源
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.titleArray.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellName = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
    }
    cell.textLabel.text = _titleArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        PicViewController *pivVC = [[PicViewController alloc] init];
        [self.navigationController pushViewController:pivVC animated:NO];
    }else if (indexPath.row == 1) {
        SleepViewController *SVC = [[SleepViewController alloc] init];
         self.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:SVC animated:NO];
    }else if (indexPath.row == 2) {
        HideCellViewController *HVC = [[HideCellViewController alloc] init];
        [self.navigationController pushViewController:HVC animated:NO];
    }


}

@end
